home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 2009 Bui Viet Thanh (thanhbv@gmail.com).
- *
- * This file is part of clicknlearn.
- *
- * clicknlearn is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * clicknlearn is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with clicknlearn. If not, see <http://www.gnu.org/licenses/>.
- */
-
- //Components.utils.import("resource://weave/log4moz.js");
-
- /**
- * Represent a Dictionary source (service)
- * @param name - name of the DicService. ex: "tratu.vn"
- * @param baseUrl - ex, "http://tratu.vn/dispatchaddon.php?dict=en_vn&title="
- * the request url will be (baseUrl + word)
- * @param notfoundPattern - if(response.indexOf(this.notfoundPattern) >= 0)
- * then we consider that the word was not found.
- * notfoundPattern can contains the string "${word} to represent the looking up word
- * @param selectors (optinal) - we don't show the whole response.
- * Ex, with HoNgocDucDicService: selectors = "#result".
- * => only show the element with id="result" in the responce html
- * see: https://developer.mozilla.org/En/DOM/Locating_DOM_elements_using_selectors
- * we can use firebug, or "Adblock Plus: Element Hiding Helper" to find selectors
- * if selectors is not specified
- */
- function DicService(name, baseUrl, notfoundPattern, selectors){
- this.name = name;
- this.baseUrl = baseUrl;
- this.notfoundPattern = notfoundPattern;
- this.selectors = typeof selectors != 'undefined' ? selectors : null;
- }
- DicService.prototype.getUrl = function(word) {
- return this.baseUrl + encodeURIComponent(word);
- }
- DicService.prototype.parseAndPrint = function(response) {
- response = this.parse(response);
-
- var html = CNLUtils.getString(
- "<label for='cnlwordbox'>${lookup} </label>" +
- "<input type='text' id='cnlwordbox' maxlength='60' size='15' value='%%' />" +
- "<button id='cnl_settingsButton' class='clicknlearnRightButton'><img src='chrome://clicknlearn/skin/settings24.png' /></button>" +
- "<br /><label for='remindbox'>${remind} </label>" +
- "<input type='text' id='remindbox' maxlength='256' size='70' value='%%' />" +
- "<br /><button class='clicknlearnButton' id='",
- [CNL.DICLOOKUP.currentWord, CNL.DICLOOKUP.currentRemind]);
- if(CNL.DICLOOKUP.remember)
- html += CNLUtils.replaceAntStyleString(
- "removeWordButton'>${knewByHeart}</button><br />");
- else
- html += CNLUtils.replaceAntStyleString(
- "remindButton'>${addNewWord}</button><br />");
- html += response;
-
- CNL.DICLOOKUP.div.innerHTML = html;
- var textbox = CNL.DICLOOKUP.div.firstChild.nextSibling;
- textbox.focus();
- }
- DicService.prototype.parse = function(response){
- if(! this.selectors)
- return response;
- var d = CNL.currentDoc.createElement('div');
- d.innerHTML = response;
- var resultDiv = d.querySelector(this.selectors);
- return resultDiv.innerHTML;
- }
-
- DicService.prototype.wordNotFound = function(response){
- // let notfoundStr = this.notfoundPattern.replace("${word}", CNL.DICLOOKUP.currentWord);
- return response.indexOf(this.notfoundPattern) >= 0;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////
-
- //function HoNgocDucDicService(){
- // this.baseUrl = "http://www.informatik.uni-leipzig.de/~duc/TD/td/index.php?db=ev&word=";
- // this.name = "Hồ Ngọc Đức";//CNL.stringsBundle.getString('hoNgocDuc');
- // this.selectors = "#result";
- //}
- //HoNgocDucDicService.prototype = new DicService();
- //
- //HoNgocDucDicService.prototype.wordNotFound = function(response){
- // var s = '<div id="result" onkeyup="lookupSelected();"> <font size=+1 color=#FF0000>';
- // var i1 = response.indexOf(s) + s.length;
- // var i2 = response.indexOf('<', i1);
- // var returnWord = response.substring(i1, i2);
- // return returnWord != CNL.DICLOOKUP.currentWord;
- //}
- ///////////////////////////////////////////////////////////////////////////////////////////////////
-
- //let logger = Log4Moz.repository.getLogger("CNL.Dicservice");
- //logger.level = Log4Moz.Level["All"];
- //logger.debug("Hồ Ngọc Đức!! " + CNL_DIC_SERVICES[4].name);
-